package models

import (
	"gorm.io/gorm"
	"time"
)

// 用户模块实现模型
type User struct {
	ID        uint      `gorm:"primaryKey;type:int unsigned" json:"id"`
	Username  string    `gorm:"size:255;unique" json:"username"`
	Password  string    `json:"password"`
	Role      string    `json:"role"`
	CreatedAt time.Time `json:"created_at"`
}

func GetUserByUsername(db *gorm.DB, username string) (User, error) {
	var user User
	result := db.Where("username = ?", username).First(&user)
	if result.Error != nil {
		return User{}, result.Error
	}
	return user, nil
}
